home *** CD-ROM | disk | FTP | other *** search
- Path: news.umbc.edu!not-for-mail
- From: schlein@umbc.edu (Jonas J. Schlein)
- Newsgroups: comp.lang.c
- Subject: Re: Problem with c code, please help!
- Date: 19 Jan 1996 17:17:36 -0500
- Organization: University of Maryland Baltimore County
- Message-ID: <4dp5a0$bh9@umbc9.umbc.edu>
- References: <surgsw-1901960148530001@128.206.206.86>
- NNTP-Posting-Host: umbc9.umbc.edu
- NNTP-Posting-User: schlein
-
- Joel Weinstein <surgsw@mizzou1.missouri.edu> wrote:
- |> I have been trying to get this very simple piece of code to work for
- |> hours. What is the problem???????
- |>
- |> #include <stdio.h>
- |>
- |> main()
- |> {
- |> int i=0;
- |> char word[100], c;
- |> printf("Enter a word: ");
- |> while( (c = getchar()) != '\n') {
-
- What does getchar() return? An int nor a char (silly huh?)...You must make 'c'
- be an int or at the very least a signed char may work.
-
- |> *word = c;
-
- This assigns 'c' to the first position of the word array so:
-
- word[0] = c;
-
- would be equivalent.
-
- |> word == word + 1;
-
- You are comparing the array 'word' with 'word' + 1. Strange! I think you're
- trying to do pointer arithmetic, but alas, an array is not a pointer so
- don't do this.
-
- |> }
- |> printf("You entered: ");
- |> *word = 0;
- |> while( *word != '\n' )
- |> {
- |> putchar( *word );
- |> word == word + 1;
-
- Again == is C's equality operator.
-
- |> }
- |> }
- |>
- |> I think the problem I am having is due to my not knowing when to use the
- |> '*' operator. When do you use it? Also, why won't my goddam compiler let
- |> me do word++; instead of word == word +1; I also tried to do *word++;
- |> and it didn't work, what is the deal with that. It won't let me put word
- |> = word + 1;. It insists on the double ='s. Why is that?
-
- Well I guess not knowing the difference between arrays and pointers as
- well as which operators do what is your problem.
- --
- "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
-
- Jonas J. Schlein (schlein@gl.umbc.edu)
-